home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / ImageWriter--custom dialogs / ChooserSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  7.5 KB  |  277 lines  |  [TEXT/MPS ]

  1. /*
  2.     ChooserSupport.c - C code for PACK and LDEF resources used by the Chooser.
  3.     
  4.     Copyright © 1992-1994 Apple Computer, Inc.
  5.     All rights reserved.
  6.  
  7.     12/20/93        dmh                Sync'd with the shipping 1.0b3 GX driver.
  8.     12/22/93        dmh                Added custom dialog code.
  9. */
  10.  
  11. #include <Types.h>
  12. #include <QuickDraw.h>
  13. #include <Fonts.h>
  14. #include <Lists.h>
  15. #include <Devices.h>
  16. #include <Resources.h>
  17. #include <Script.h>
  18. #include <ToolUtils.h>
  19. #include <SysEqu.h>
  20.  
  21. #include "graphics routines.h"
  22. #include <PrintingDrivers.h>
  23.  
  24. // ------------------------------------------------------------------------
  25. // INTERNAL DEFINES
  26. // ------------------------------------------------------------------------
  27. // Chooser initialize message selector
  28. #define initializeMsg    11
  29.  
  30. // Icon Suite support
  31. #define ttNone        0x0000
  32. #define ttDisabled    0x0001
  33. #define    ttOffline    0x0002
  34. #define ttOpen        0x0003
  35. #define ttSelected     0x4000
  36. #define ttSelectedDisabled    (ttSelected + ttDisabled)
  37. #define ttSelectedOffline    (ttSelected + ttOffline)
  38. #define ttSelectedOpen        (ttSelected + ttOpen)
  39.  
  40. #define ttLabel0    0x0000
  41. #define ttLabel1    0x0100
  42. #define ttLabel2    0x0200
  43. #define ttLabel3    0x0300
  44. #define ttLabel4    0x0400
  45. #define ttLabel5    0x0500
  46. #define ttLabel6    0x0600
  47. #define ttLabel7    0x0700
  48. pascal OSErr PlotIconSuite(const Rect * theRect, short align, short iconTransform, Handle cIcon)
  49.     = {0x303C, 0x0603, 0xABC9};
  50.  
  51. // Copy of the DrawText trap
  52. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  53.     = 0xA885; 
  54.  
  55. // ------------------------------------------------------------------------
  56. // MAIN CODE FOR PACK
  57. // ------------------------------------------------------------------------
  58. pascal OSErr Device(short message, short caller, StringPtr objName, 
  59.     StringPtr zoneName, ListHandle theList, long p2)
  60. {
  61.     
  62.     OSErr            anErr = noErr;
  63.     extern Str31     gDriverName;
  64.     StringPtr        pDriverName = &gDriverName;
  65.     extern gxJob    gJob;
  66.     gxJob            *pJob = &gJob;
  67.     
  68.     // start up GX to begin with
  69.     if (message == initializeMsg)
  70.         {
  71.         FCBPBRec    pb;
  72.  
  73.         // determine the driver name
  74.         pb.ioCompletion     = nil;
  75.         pb.ioNamePtr         = pDriverName;
  76.         pb.ioVRefNum         = 0;
  77.         pb.ioRefNum         = CurResFile();
  78.         pb.ioFCBIndx         = 0;
  79.         anErr = PBGetFCBInfo(&pb, false);
  80.  
  81.         *pJob = nil;
  82.         if (anErr == noErr)
  83.             {
  84.             GXEnterGraphics();
  85.             anErr = GXGetGraphicsError(nil);
  86.             if (anErr == noErr)
  87.                 {
  88.                 anErr = GXInitPrinting();
  89.                 if (anErr != noErr)
  90.                     GXExitGraphics();
  91.                 }
  92.                 
  93.             if (anErr != noErr)
  94.                 StopAlert(-4095, nil);
  95.             }
  96.         }
  97.         
  98.     // let the system handle the choosing for us (how nice of it!)
  99.     if (anErr == noErr)
  100.         {
  101.         if ((*pJob != nil) || (message == initializeMsg))
  102.             {
  103.             anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  104.         
  105.             // tear down GX when done
  106.             if ( (message == terminateMsg) && (p2 == terminateMsg) )
  107.                 {
  108.                 GXExitPrinting();
  109.                 GXExitGraphics();
  110.                 }
  111.             }
  112.         }
  113.         
  114.     return(anErr);
  115.     
  116. } // Device
  117.  
  118.  
  119.  
  120. // ------------------------------------------------------------------------
  121. // ENTRY POINT FOR LDEF
  122. // ------------------------------------------------------------------------
  123.  
  124. pascal void LDEF(
  125.     short         message,        // What operation to perform on list
  126.     Boolean     select,            // Is this cell to be selected or not?
  127.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  128.     Cell        theCell,        // Which cell this is
  129.     short        dataOffset,        // Offset into data for this cell
  130.     short        dataLen,        // Length of data for this cell
  131.     ListHandle    theList)        // The list to act upon
  132. /*
  133.     An LDEF that works in two modes:
  134.         - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
  135.           then the LDEF is just a basic text LDEF
  136.         - otherwise, it assumes the data is part of a PortListRec, which is
  137.           a structure for icons with text underneath
  138. */
  139.  
  140. {
  141. #pragma unused (theCell, dataLen)
  142.  
  143.     gxPortListRec        theCellContents;
  144.     Rect                iconRect;
  145.     
  146.     switch (message)
  147.         {
  148.         case lDrawMsg:
  149.         case lHiliteMsg:
  150.         
  151.             // save the data to avoid locking things down
  152.             if (dataLen > sizeof(theCellContents) )
  153.                 dataLen = sizeof(theCellContents);
  154.             BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
  155.             
  156.             // draw the cell as an icon, but only if we see our magic marker at the front
  157.             if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
  158.                 {
  159.                 // center the icon rect on the list with a top margin of 10 pixels
  160.                 iconRect.top = theRect->top + 10;
  161.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  162.                 iconRect.bottom = iconRect.top + 32;
  163.                 iconRect.right = iconRect.left + 32;
  164.                 
  165.                 
  166.                 // draw the icon
  167.                 if (theCellContents.iconSuiteHandle != nil)
  168.                     PlotIconSuite(&iconRect,
  169.                             ttNone, (select) ? ttSelected: ttNone,
  170.                             theCellContents.iconSuiteHandle);
  171.                             
  172.                 // Get the general area under the icon in which to draw the label
  173.                 iconRect.left = theRect->left + 2;
  174.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  175.                 iconRect.top = iconRect.bottom + 2;
  176.                 iconRect.bottom = theRect->bottom;
  177.     
  178.                 // use a nice small font for the label            
  179.                 TextFont(applFont);
  180.                 TextSize(9);
  181.                 
  182.                     {
  183.                     short        labelWidth;
  184.                     short        rectWidth;
  185.                     short        labelHeight;
  186.                     FontInfo    theInfo;
  187.                 
  188.                     // Get rid of any text that was there before
  189.                     EraseRect(&iconRect);
  190.                     iconRect.top += 2;
  191.                     
  192.                     // compute the height of the label                    
  193.                     GetFontInfo(&theInfo);
  194.                     labelHeight = theInfo.ascent + theInfo.leading;
  195.                     
  196.                     // compute where to draw the text
  197.                     iconRect.bottom = iconRect.top + labelHeight;
  198.                     rectWidth = iconRect.right-iconRect.left;
  199.                     
  200.                     // truncate the string to fit within the box
  201.                     TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
  202.                     
  203.                     // compute the new width of the string
  204.                     labelWidth = StringWidth(theCellContents.iconName);
  205.                     
  206.                     // center the string, draw it
  207.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  208.                     MoveTo(iconRect.left, iconRect.bottom);
  209.                     DrawString(theCellContents.iconName);
  210.                     
  211.                     if (select)
  212.                         {
  213.                         // compute right and lower edge of box bounding the text we just drew
  214.                         iconRect.right = iconRect.left + labelWidth;
  215.                         iconRect.bottom += theInfo.descent;
  216.                         
  217.                         // outset it, and invert it to select it
  218.                         InsetRect(&iconRect, -1, -1);
  219.                         BitClr((Ptr) HiliteMode, pHiliteBit);
  220.                         InvertRect(&iconRect);
  221.                         }
  222.                     }
  223.                     
  224.                 TextFont(applFont);
  225.                 TextSize(0);
  226.                 }
  227.             else
  228.                 {
  229.                 // how boring!  It's only text
  230.                 FontInfo    theInfo;
  231.                 Rect        ourRect;
  232.                 short        cellWidth;
  233.                 
  234.                 // add a margin to the rectangle
  235.                 ourRect = *theRect;
  236.                 ourRect.left += 4;
  237.                 --ourRect.right;
  238.                 cellWidth = ourRect.right - ourRect.left;
  239.                 
  240.                 // erase the rectangle
  241.                 GetFontInfo(&theInfo);
  242.                 EraseRect(theRect);
  243.                 MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
  244.                 
  245.                 // hey, you can't park that string here -- it's too big!
  246.                 if (TextWidth((Ptr) &theCellContents, 0, dataLen) > cellWidth )
  247.                     {
  248.                     // condense the text first
  249.                     TextFace(condense);
  250.                     
  251.                     // then truncate afterwards
  252.                     TruncText(cellWidth, (Ptr) &theCellContents, &dataLen, smTruncEnd);
  253.                     }
  254.                     
  255.                 // those darn other languages!
  256.                 if (GetSysJust() == teJustRight)
  257.                     Move(cellWidth-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
  258.                     
  259.                 OldDrawText((Ptr) &theCellContents, 0, dataLen);
  260.                 
  261.                 // if selected, invert it
  262.                 if (select)
  263.                     {
  264.                     BitClr((Ptr) HiliteMode, pHiliteBit);
  265.                     InvertRect(theRect);
  266.                     }
  267.                     
  268.                 // normal text again
  269.                 TextFace(normal);
  270.                 }
  271.                 
  272.             break;
  273.             
  274.         } // switch
  275.         
  276. } // LDEF
  277.